package com.ac.api.user.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.base.helper.StringUtils;
import com.ac.api.user.dao.AcUsertypeMapper;
import com.ac.api.user.entity.AcUsertype;
import com.ac.api.user.service.AcUsertypeService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author mzl
 * @since 2020-07-09
 */
@Service
public class AcUsertypeServiceImpl extends ServiceImpl<AcUsertypeMapper, AcUsertype> implements AcUsertypeService {

    @Override
    public List<AcUsertype> list(AcUsertype example) {
        return this.list(buildWrapper(example));
    }

    @Override
    public IPage<AcUsertype> page(AcUsertype example, IPage page) {
        return this.page(page, buildWrapper(example));
    }

    private QueryWrapper<AcUsertype> buildWrapper(AcUsertype example) {
        QueryWrapper<AcUsertype> wrapper = new QueryWrapper<>(example);
        String                   name    = example.getName();
        wrapper.lambda().like(StringUtils.isNotEmpty(name), AcUsertype::getName, name)
                .orderByAsc(AcUsertype::getId);
        return wrapper;
    }

}
